<template>
  <view class="content">
    <!-- <text class="success-icon yticon icon-xuanzhong2"></text> -->
    <text class="success-icon"></text>

    <view class="info">
      <view class="v1"><text class="tit iconfont icon-a-selects"></text></view>
      <view class="v2">
        <text class="price">
          <text style="font-size: 40rpx">¥</text>
          {{ price }}
        </text>
      </view>
      <view class="v3"><text class="">订单支付成功</text></view>
    </view>

    <view class="btn-group">
      <!-- 返回首页没有修改下标 -->
      <view class="btn-groupV1" @click="goPageIndex"> 回到首页 </view>
      <!-- <navigator url="/pages/index/index" open-type="switchTab" class="mix-btn hollow">返回首页</navigator> -->
      <!-- <navigator :url="orderUrl" open-type="redirect" class="mix-btn">查看订单</navigator> -->
      <view v-if="type == 'medicalType'" @click="goChat" class="btn-groupV2"
        >进入诊室</view
      >
      <view v-else class="btn-groupV2" @click="goOrderPage()"> 查看订单 </view>
    </view>
  </view>
</template>

<script>
import { mapMutations, mapActions } from 'vuex'

export default {
  data() {
    return {
      orderUrl: 'server/orderList',
      price: '',
      type: '',
      outTradeNo: '', //问诊订单号
      docInfo: {}, //问诊单的医生信息
    }
  },
  methods: {
    ...mapMutations('common', ['SET_TABBAR']),
    ...mapActions('user', ['IMLogin']),

    goPageIndex() {
      this.SET_TABBAR(0)
      uni.switchTab({
        url: '/pages/index/index',
      })
    },
    goChat() {
      console.log('医生信息', this.docInfo)
      if (!uni.$TUIKit) {
        console.log('chat--im登录返回')
        // uni.navigateTo({
        //   url: `/packageAuth/pages/authorization/IMLoading?url=${encodeURIComponent(`/packageMedical/pages/TUI-Chat/chat?conversationID=C2C${this.docInfo.id}&nickName=${this.docInfo.trueName}`)}`,
        // })
        this.toPage(
          `/packageAuth/pages/authorization/IMLoading?url=${encodeURIComponent(
            `/packageMedical/pages/TUI-Chat/chat?conversationID=C2C${this.docInfo.id}&nickName=${this.docInfo.trueName}`
          )}`
        )
      } else {
        console.log('isIMLogin', uni.getStorageSync('isIMLogin'))
        if (uni.getStorageSync('isIMLogin')) {
          this.toPage(
            `/packageMedical/pages/TUI-Chat/chat?conversationID=C2C${this.docInfo.id}&nickName=${this.docInfo.trueName}`
          )
        } else {
          this.IMLogin().then(res => {
            this.toPage(
              `/packageMedical/pages/TUI-Chat/chat?conversationID=C2C${this.docInfo.id}&nickName=${this.docInfo.trueName}`
            )
          })
        }
      }
    },
    goOrderPage() {
      // if (this.type == 'equipment') {
      //   this.orderUrl = '/pages/equipment/orderEquipment';
      // }
      if (this.type == 'medicalType') {
        //问诊下单
        this.orderUrl = `/packageMedical/pages/medical/inquiryList?state=2&outTradeNo=${this.outTradeNo}`
      }
      if (this.type == 'server') {
        //医院服务下单
        this.orderUrl = `/pages/server/orderList`
      }
      // if (this.type == 'protect') { //联盟捐粮列表 回跳
      //   this.orderUrl = '/pages/alliance/protect'
      // }
      // if (this.type == 'intelligence') { //智商联盟报名 回跳
      //   this.orderUrl = '/pages/alliance/Intelligence'
      // }

      if (this.type == 'medicalTypeGoBack') {
        //medicalTypeGoBack   这是问诊订单页的去付款
        this.goBack()
        return
      }
      uni.redirectTo({
        url: this.orderUrl,
      })
    },
  },
  onLoad(options) {
    this.price = options.price
    this.type = options.type
    console.log('支付类型', this.type)
    if (options.outTradeNo) {
      this.outTradeNo = options.outTradeNo
    }
    if (options.docInfo) this.docInfo = JSON.parse(options.docInfo)
  },
}
</script>

<style lang="scss">
.content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.success-icon {
  font-size: 160rpx;
  color: $base-color;
  margin-top: 100rpx;
}
.tit {
  font-size: 38rpx;
  color: #FF5900;
}
.btn-group {
  width: 550rpx;
  display: flex;
  justify-content: space-evenly;
  padding-top: 100rpx;
}
.mix-btn {
  margin-top: 30rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 224rpx;
  height: 80rpx;
  font-size: $font-lg;
  color: #fff;
  background-color: $base-color;
  border-radius: 40rpx;
  &.hollow {
    background: #fff;
    color: #303133;
    border: 1px solid #ccc;
  }
}

.info {
  text-align: center;
  .v2 {
    margin-top: 0rpx;
    .price {
      font-size: 56rpx;
      font-family: DIN-Medium, DIN;
      font-weight: 500;
      color: #121212;
      line-height: 56rpx;
    }
  }
  .v3 {
    text {
      font-size: 28rpx;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 28rpx;
    }
  }
}

.btn-groupV1 {
  width: 224rpx;
  height: 80rpx;
  border-radius: 40rpx;
  border: 2rpx solid #e6e6e6;
  text-align: center;

  font-size: 32rpx;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #666666;
  line-height: 76rpx;
}

.btn-groupV2 {
  width: 224rpx;
  height: 80rpx;
  border-radius: 40rpx;
  border: 2rpx solid #FF5900;

  text-align: center;
  font-size: 32rpx;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #FF5900;
  line-height: 76rpx;
}
</style>
